package com.hkts.naturalgas.utils;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassNameDataSummary
 * @Description
 * @Author yck
 * @Date2021-11-10 15:52
 * @Version V1.0
 **/
public class DataSummary {
    public static Map<String, Object> getCargoAndOrder() {
        String URL = "jdbc:mysql://124.70.102.57:8066/order_0?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT";
        String USER = "mycat";
        String PASSWORD = "hkts!@#$";
        Connection conn = null;
        Statement st = null;
        Map<String, Object> resultMap = new HashMap<>();
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
        String format = sim.format(new Date());
        //1.加载驱动程序
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            //设置超时时间
            DriverManager.setLoginTimeout(1);
            //2.获得数据库链接
            conn = DriverManager.getConnection(URL, USER, PASSWORD);
            st = conn.createStatement();
            //3.通过数据库的连接操作数据库，实现增删改查（使用Statement类）
            ResultSet rs = st.executeQuery("select count(*) count from hkts_cargo where CREATE_TIME > '"+format+"' ");
            while (rs.next()) {
                int countCargo = rs.getInt("count");
                resultMap.put("今日发货数量", countCargo);
            }
            ResultSet rsOrder = st.executeQuery("select count(*) count from hkts_order where CREATE_TIME > '"+format+"' ");
            while (rsOrder.next()) {
                int countOrder = rsOrder.getInt("count");
                resultMap.put("今日订单数量", countOrder);
            }
            rs.close();
            rsOrder.close();
        } catch (Exception e) {

            e.printStackTrace();
        } finally {
            try {
                if (st != null) {
                    st.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        //4.处理数据库的返回结果(使用ResultSet类)
        //关闭资源
        return resultMap;
    }

    public static Map<String, Object> getUserInfo() {
        String URL = "jdbc:mysql://124.70.102.57:8066/transportation_auth?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT";
        String USER = "mycat";
        String PASSWORD = "hkts!@#$";
        Connection conn = null;
        Statement st = null;
        Map<String, Object> resultMap = new HashMap<>();
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
        String format = sim.format(new Date());
        //1.加载驱动程序
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            //设置超时时间
            DriverManager.setLoginTimeout(1);
            //2.获得数据库链接
            conn = DriverManager.getConnection(URL, USER, PASSWORD);
            st = conn.createStatement();
            //3.通过数据库的连接操作数据库，实现增删改查（使用Statement类）
            ResultSet rsAppro = st.executeQuery("select count(*) count from hkts_real_name_authentication where approval_time>'"+format+"'");
            while (rsAppro.next()) {
                int countRsAppro = rsAppro.getInt("count");
                resultMap.put("今日通过认证司机数量", countRsAppro);
            }
            ResultSet rsNew = st.executeQuery("select count(*) count from hkts_driver where CREATE_TIME > '"+format+"' ");
            while (rsNew.next()) {
                int countNew = rsNew.getInt("count");
                resultMap.put("今日新增司机数量", countNew);
            }
            ResultSet rsLOG = st.executeQuery("select count(*) count from management_log where CREATE_TIME > '"+format+"' ");
            while (rsLOG.next()) {
                int countLog = rsLOG.getInt("count");
                resultMap.put("今日登录司机数量", countLog);
            }
            rsAppro.close();
            rsNew.close();
            rsLOG.close();
        } catch (Exception e) {

            e.printStackTrace();
        } finally {
            try {
                if (st != null) {
                    st.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        //4.处理数据库的返回结果(使用ResultSet类)
        //关闭资源
        return resultMap;
    }
}
